package cn.dengta.webapp.trade.model;

import java.util.Date;
import javax.annotation.Nullable;

import cn.dengta.common.model.ErrorMessageException;
import cn.dengta.common.model.Messager;
import me.codeplayer.util.Assert;
import me.codeplayer.util.StringUtil;

public interface AuditScoped {

	AuditScoped setVerifyTime(Date verifyTime);

	AuditScoped setVerifyUserId(Long verifyUserId);

	AuditScoped setVerifyRemark(String verifyRemark);

	AuditScoped setReviewTime(Date reviewTime);

	AuditScoped setReviewUserId(Long reviewUserId);

	AuditScoped setReviewRemark(String reviewRemark);

	void setStatus(Integer status);

	Integer getStatus();

	/**
	 * 审核添加，审核状态为已驳回时，必须要填写备注
	 */
	default void applyAudit(Long auditUserId, Integer currentStatus, Integer verifyStatus, @Nullable String auditRemark, AuditLevel level, Date now) {
		// 防止远程调用超时，实际请求成功，判断状态是否成功
		if (currentStatus == 99) {
			throw new ErrorMessageException(Messager.OK());
		}
		Assert.isTrue(level.checkValidate(currentStatus), "审核流程不正确，请核实！");
		switch (level) {
			case VERIFY:
				setVerifyUserId(auditUserId);
				setVerifyTime(now);
				setVerifyRemark(StringUtil.toString(auditRemark));
				break;
			case REVIEW:
				setReviewUserId(auditUserId);
				setReviewTime(now);
				setReviewRemark(StringUtil.toString(auditRemark));
				break;
		}
		setStatus(verifyStatus);
	}

}
